//
//  ZYCProtalNoticeImageCollectionCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/19.
//

#import "ZYCProtalNoticeImageCollectionCell.h"
#import <UIImageView+WebCache.h>
#import "ZYCNewBulletinModel.h"

@interface ZYCProtalNoticeImageCollectionCell ()

@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation ZYCProtalNoticeImageCollectionCell

- (void)setModel:(ZYCNoticeFileModel *)model{
    _model = model;
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.filePath]];
    [_imageView sd_setImageWithURL:url];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];

    }
    return self;
}


- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _imageView;
}

- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    [self setNeedsLayout];
    [self layoutIfNeeded];
    CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
    CGRect cellFrame = layoutAttributes.frame;
    cellFrame.size.height = size.height;
    layoutAttributes.frame = cellFrame;
    return layoutAttributes;
}


@end
